from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from utils.driver_aolai import Driver
import time


class BaseObject:
    def __init__(self):
        self.driver = Driver.get_app_driver()

    def search_ele(self, loc, timeout=5, poll_frequency=1.0):
        # WebDriverWait(self.driver,timeout,poll).until(lambda x:x.find_element(ty,value))
        return WebDriverWait(self.driver, timeout, poll_frequency).until(lambda x: x.find_element(loc[0], loc[1]))

    def search_eles(self, loc, timeout=5, poll_frequency=1.0):
        # WebDriverWait(self.driver,timeout,poll).until(lambda x:x.find_element(ty,value))
        return WebDriverWait(self.driver, timeout, poll_frequency).until(lambda x: x.find_elements(loc[0], loc[1]))


class BaseHandle:
    def input(self, ele, value):
        ele.clear()
        ele.send_keys(value)


if __name__ == '__main__':
    b = BaseObject()
    a = b.search_ele((By.ID, 'com.android.settings:id/search'))
    a.click()
    time.sleep(2)
    c = b.search_ele((By.ID, 'android:id/search_src_text'))
    d = BaseHandle()
    time.sleep(1)
    d.input(c, 1)
